home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / protocols / classic.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  158 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __all__ = [
  5.     'ProviderMixin']
  6. from types import FunctionType, ModuleType, InstanceType, ClassType
  7. from adapters import *
  8. from api import declareImplementation, advise, declareAdapterForObject, adapt
  9. from interfaces import *
  10. from new import instancemethod
  11. from advice import getMRO, metamethod, mkRef
  12.  
  13. class ProviderMixin:
  14.     advise(instancesProvide = [
  15.         IOpenProvider,
  16.         IImplicationListener])
  17.     
  18.     def declareProvides(self, protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  19.         registry = self.__dict__.get('__protocols_provided__')
  20.         if registry is None:
  21.             self.__protocols_provided__ = registry = { }
  22.         
  23.         if updateWithSimplestAdapter(registry, protocol, adapter, depth):
  24.             adapt(protocol, IOpenProtocol).addImplicationListener(self)
  25.             return True
  26.         
  27.  
  28.     declareProvides = metamethod(declareProvides)
  29.     
  30.     def newProtocolImplied(self, srcProto, destProto, adapter, depth):
  31.         registry = self.__dict__.get('__protocols_provided__', ())
  32.         if srcProto not in registry:
  33.             return None
  34.         
  35.         (baseAdapter, d) = registry[srcProto]
  36.         adapter = composeAdapters(baseAdapter, srcProto, adapter)
  37.         declareAdapterForObject(destProto, adapter, self, depth + d)
  38.  
  39.     newProtocolImplied = metamethod(newProtocolImplied)
  40.     
  41.     def __conform__(self, protocol):
  42.         for cls in getMRO(self):
  43.             conf = cls.__dict__.get('__protocols_provided__', ())
  44.             if protocol in conf:
  45.                 return conf[protocol][0](self)
  46.                 continue
  47.         
  48.  
  49.     __conform__ = metamethod(__conform__)
  50.  
  51.  
  52. class conformsRegistry(dict):
  53.     
  54.     def __call__(self, protocol):
  55.         if protocol in self:
  56.             subject = self.subject()
  57.             if subject is not None:
  58.                 return self[protocol][0](subject)
  59.             
  60.         
  61.  
  62.     
  63.     def findImplementation(self, subject, protocol, checkSelf = True):
  64.         for cls in getMRO(subject):
  65.             conf = cls.__dict__.get('__conform__')
  66.             if conf is None:
  67.                 continue
  68.             
  69.             if not isinstance(conf, conformsRegistry):
  70.                 raise TypeError('Incompatible __conform__ in base class', conf, cls)
  71.             
  72.             if protocol in conf:
  73.                 return conf[protocol][0](subject)
  74.                 continue
  75.         
  76.  
  77.     
  78.     def newProtocolImplied(self, srcProto, destProto, adapter, depth):
  79.         subject = self.subject()
  80.         if subject is None or srcProto not in self:
  81.             return None
  82.         
  83.         (baseAdapter, d) = self[srcProto]
  84.         adapter = composeAdapters(baseAdapter, srcProto, adapter)
  85.         declareAdapterForObject(destProto, adapter, subject, depth + d)
  86.  
  87.     
  88.     def __hash__(self):
  89.         return id(self)
  90.  
  91.     
  92.     def __get__(self, ob, typ = None):
  93.         if ob is not None:
  94.             raise AttributeError('__conform__ registry does not pass to instances')
  95.         
  96.         return instancemethod(self.findImplementation, typ, type(typ))
  97.  
  98.     
  99.     def __getstate__(self):
  100.         return (self.subject(), self.items())
  101.  
  102.     
  103.     def __setstate__(self, .1):
  104.         (subject, items) = .1
  105.         self.clear()
  106.         self.update(dict(items))
  107.         self.subject = mkRef(subject)
  108.  
  109.  
  110.  
  111. class MiscObjectsAsOpenProvider(object):
  112.     advise(instancesProvide = [
  113.         IOpenProvider], asAdapterForTypes = [
  114.         FunctionType,
  115.         ModuleType,
  116.         InstanceType,
  117.         ClassType,
  118.         type,
  119.         object])
  120.     
  121.     def __init__(self, ob):
  122.         obs = list(getMRO(ob))
  123.         for item in obs:
  124.             
  125.             try:
  126.                 reg = item.__dict__.get('__conform__')
  127.                 if reg is None and obs == [
  128.                     ob]:
  129.                     reg = getattr(item, '__conform__', None)
  130.             except AttributeError:
  131.                 raise TypeError('Only objects with dictionaries can use this adapter', ob)
  132.  
  133.             if reg is not None and not isinstance(reg, conformsRegistry):
  134.                 raise TypeError('Incompatible __conform__ on adapted object', ob, reg)
  135.                 continue
  136.         
  137.         reg = ob.__dict__.get('__conform__')
  138.         if reg is None:
  139.             reg = ob.__conform__ = self.newRegistry(ob)
  140.         
  141.         self.ob = ob
  142.         self.reg = reg
  143.  
  144.     
  145.     def declareProvides(self, protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  146.         if updateWithSimplestAdapter(self.reg, protocol, adapter, depth):
  147.             adapt(protocol, IOpenProtocol).addImplicationListener(self.reg)
  148.             return True
  149.         
  150.  
  151.     
  152.     def newRegistry(self, subject):
  153.         reg = conformsRegistry()
  154.         reg.subject = mkRef(subject)
  155.         return reg
  156.  
  157.  
  158.